package array;

/**
 * @author 十八岁讨厌编程
 * @date 2025/6/27 21:01
 * @PROJECT_NAME leetcode
 * @description
 */

public class Solution977 {
    class Solution {
        public int[] sortedSquares(int[] nums) {
            int head = 0;
            int end = nums.length -1;
            int[] result = new int[nums.length];
            int write = nums.length -1;
            while(head <= end) {
                int headNum = (int)Math.pow(nums[head],2);
                int endNum = (int)Math.pow(nums[end],2);
                if(headNum >= endNum) {
                    result[write--] = headNum;
                    head++;
                }else {
                    result[write--] = endNum;
                    end--;
                }
            }
            return result;
        }
    }

}
